package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsFootprintMapper;
import com.qf.pojo.DtsFootprint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author Wy
 * @version V1.0
 * @Project MavenDemo
 * @Package com.qf.service
 * @Description:
 * @Date 2022/7/8 22:23
 */
@Service
public class footprintServiceImpl implements footprintService {

    @Autowired
    private DtsFootprintMapper mapper;
    @Override
    public IPage<DtsFootprint> list(String userId, String goodsId, Integer page, Integer limit, String sort, String order) {
        IPage<DtsFootprint> page1 = new Page<>(page,limit);
        QueryWrapper<DtsFootprint> queryWrapper = new QueryWrapper<>();
           queryWrapper.eq("deleted", false);
           if(!StringUtils.isEmpty(userId)){
                queryWrapper.eq("user_id", userId);
           }
           if(!StringUtils.isEmpty(goodsId)){
               queryWrapper.eq("goods_id", goodsId);
           }
           if(!StringUtils.isEmpty(sort)&&!StringUtils.isEmpty(order)){

               if(order.equalsIgnoreCase("asc")){
                   queryWrapper.orderByAsc();
               }else {
                   queryWrapper.orderByDesc();
               }
           }
        IPage<DtsFootprint> dtsFootprintIPage = mapper.selectPage(page1, queryWrapper);
        return dtsFootprintIPage;
    }
}
